package com.eling.elcms.travel.service.impl;

import com.eling.elcms.community.model.Department;
import com.eling.elcms.community.service.IDepartmentManager;
import com.eling.elcms.core.model.BaseModel;
import com.eling.elcms.privilege.model.User;
import com.eling.elcms.travel.service.IApprovalRule;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@Service
public class DepartmentApprovalRule implements IApprovalRule {
	
	@Autowired
	IDepartmentManager departmentManager;

	@Override
	public Map<String, String> candidatePara() {
		Map<String, String> map = new HashMap<>();
		Department cond = new Department();
		cond.setSeal(false);
		List<Department> list = departmentManager.query(cond);
		for (Iterator<Department> iterator = list.iterator(); iterator.hasNext();) {
			Department department = (Department) iterator.next();
			map.put(department.getPkDepartment().toString(), department.getName());
		}
		return map;
	}

	@Override
	public User getApproval(String para, BaseModel model) {
		return departmentManager.get(Long.valueOf(para)).getManager();
	}

}
